package software.hust.com.hust_last.presenter;

import software.hust.com.hust_last.MyApplication;
import software.hust.com.hust_last.view.AddTreasureActivity;
import software.hust.com.hust_last.network.AddTreasureData;
import software.hust.com.hust_last.network.BaseResponse;
import software.hust.com.hust_last.callback.ObjectCallback;
import software.hust.com.hust_last.util.AppConfig;
import software.hust.com.hust_last.util.ToastUtil;

/**
 * Created by zwjian on 2017/11/13.
 */

public class AddTreasurePresenter extends BasePresenter<AddTreasureActivity> {

    private String userID = MyApplication.mApplication.loginUserInfo.user_id + "";
    private String token = MyApplication.mApplication.loginUserInfo.user_token + "";

    public AddTreasurePresenter(AddTreasureActivity view) {
        super(view);
    }

    /**
     * @des 添加宝藏
     */
    public void addTreasure(String longitude, String latitude, String treasure_city,
                            String treasure_spot, String treasure_name, String prop_id
            , String treasure_remark, String treasure_type, String treasure_password, String hide_time
            , String end_time, String reward_type, String treasure_money, String assign_type
            , String num, String radius) {

        AddTreasureData data = new AddTreasureData();
        data.user_id = userID;
        data.user_token = token;
        data.longitude = longitude;
        data.latitude = latitude;
        data.treasure_city = treasure_city;
        data.treasure_spot = treasure_spot;
        data.treasure_name = treasure_name;
        data.prop_id = prop_id;
        data.treasure_remark = treasure_remark;
        data.treasure_type = treasure_type;
        data.treasure_password = treasure_password;
        data.hide_time = hide_time;
        data.end_time = end_time;
        data.reward_type = reward_type;
        data.treasure_money = treasure_money;
        data.assign_type = assign_type;
        data.num = num;
        data.radius = radius;

        data.request(this, new ObjectCallback<BaseResponse>() {
            @Override
            public void onSuccess(int responseCode, BaseResponse response) {
                if ("100".equals(response.result_code)) {
                    ToastUtil.show(getView(), "藏宝失败，请稍后重试");
                    return;
                }
                if ("101".equals(response.result_code)) {
                    ToastUtil.show(getView(), "登录异常，请重新登录再次尝试");
                    return;
                }
                if ("102".equals(response.result_code)) {
                    ToastUtil.show(getView(), "您的积分不足，藏宝失败");
                    return;
                }
                if ("105".equals(response.result_code)) {
                    ToastUtil.show(getView(), "您的金钱不足，请充值");
                    return;
                }

                if (AppConfig.NET_SUCCESS.equals(response.result_code) && getView() != null) {
                    getView().AddTreasureSuccess();
                }
            }

            @Override
            public void onFailure(String errMsg) {
                ToastUtil.show(getView(), "藏宝失败，请稍后重试");
            }
        });
    }
}
